package org.design.log.listener;

import lombok.extern.slf4j.Slf4j;
import org.design.log.biz.service.ApiLogService;
import org.design.log.entity.ApiLog;
import org.design.log.event.ApiLogEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * ApiLogListener
 *
 * @author 樊温军
 * @date 2025/6/23 上午9:06
 */
@Slf4j
@Component
public class ApiLogListener {
    private ApiLogService apiLogService;

    @Autowired
    public void setApiLogService(ApiLogService apiLogService) {
        this.apiLogService = apiLogService;
    }

    @Async
    @Order
    @EventListener(ApiLogEvent.class)
    public void saveSysLog(ApiLogEvent event) {
        ApiLog apiLog = event.getApiLog();
        apiLogService.saveLog(apiLog);
    }
}
